<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>随便打TCS系统</title>
    <!-- Bootstrap -->
    <link href="<%=basePath%>vendors/bootstrap/dist/css/bootstrap.min.css"
          rel="stylesheet">
    <!-- Font Awesome -->
    <link
            href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
            rel="stylesheet">
    <!-- NProgress -->
    <link href="<%=basePath%>vendors/nprogress/nprogress.css"
          rel="stylesheet">
    <!-- iCheck -->
    <link href="<%=basePath%>vendors/iCheck/skins/flat/green.css"
          rel="stylesheet">

    <!-- bootstrap-progressbar -->
    <link
            href="<%=basePath%>vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css"
            rel="stylesheet">
    <!-- JQVMap -->
    <link href="<%=basePath%>vendors/jqvmap/dist/jqvmap.min.css"
          rel="stylesheet"/>
    <!-- bootstrap-daterangepicker -->
    <link
            href="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.css"
            rel="stylesheet">

    <!-- Custom Theme Style -->
    <link href="<%=basePath%>build/css/custom.min.css" rel="stylesheet">
    <script type="text/javascript"
            src="http://api.map.baidu.com/api?v=2.0&ak=mENaiMKmd5sLVYOekAd3z9vmjOtkUS7m"></script>
</head>
<%@ include file="loginCheck.jsp" %>
<body class="nav-md">
<div class="container body">
    <div class="main_container">
        <div class="col-md-3 left_col">
            <div class="left_col scroll-view">
                <div class="clearfix"></div>
                <br/>
            </div>
        </div>
        <!-- page content -->
        <div class="right_col" role="main">
            <div class="">
                <div class="clearfix"></div>
                <div class="row">
                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <div class="x_panel">
                            <div class="x_content">
                                <form name="myForm" class="form-horizontal form-label-left"
                                      novalidate method="post" enctype="multipart/form-data"
                                      id="myForm">
                                    <span class="section">店铺信息</span>
                                    <div class="item form-group" style="display: none">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                               for="name">id<span class="required"></span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input id="id" name="id"
                                                   class="form-control col-md-7 col-xs-12" type="text"
                                                   value="${selfShop.id}">
                                        </div>
                                    </div>

                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                               for="name">店铺名称</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input class="form-control col-md-7 col-xs-12"
                                                   name="shopname" placeholder="" required="required"
                                                   type="text" value="${selfShop.shopname}" id="shopname">
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                               for="name">店铺LOGO</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input class="form-control col-md-7 col-xs-12" id="logoFile"
                                                   name="logoFile" required="required" type="file"
                                                   placeholder="请先上传图片" form="formUpload"> <input
                                                id="shoplogo" name="shoplogo"
                                                class="form-control col-md-7 col-xs-12"
                                                style="display: none" type="text"
                                                value="${selfShop.shoplogo}">
                                        </div>
                                    </div>
                                    <c:if test="${selfShop.shoplogo != null}">
                                        <div class="item form-group">
                                            <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                                   for="name"><span class="required"></span>
                                            </label>
                                            <div class="col-md-6 col-sm-6 col-xs-12">
                                                <img src="${selfShop.shoplogo}" style="width: 790px;hight: 380px;"
                                                     alt="图片未读取"/>
                                            </div>
                                        </div>
                                    </c:if>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                               for="name">商城背景</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input class="form-control col-md-7 col-xs-12" id="bgFile"
                                                   name="bgFile" required="required" type="file"
                                                   placeholder="请先上传图片" form="formUpload"> <input
                                                id="shopbg" name="shopbg"
                                                class="form-control col-md-7 col-xs-12"
                                                style="display: none;" type="text"
                                                value="${selfShop.shopbg}">
                                        </div>
                                    </div>
                                    <c:if test="${selfShop.shopbg != null}">
                                        <div class="item form-group">
                                            <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                                   for="name"><span class="required"></span>
                                            </label>
                                            <div class="col-md-6 col-sm-6 col-xs-12">
                                                <img src="${selfShop.shopbg}" style="width: 790px;hight: 380px;"
                                                     alt="图片未读取"/>
                                            </div>
                                        </div>
                                    </c:if>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                               for="name">店铺地址</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input class="form-control col-md-7 col-xs-12"
                                                   name="address" placeholder="为了确保定位准确，请输入详细的地址信息，例如：杭州市新塘路杭州新传媒产业大厦"
                                                   required="required" type="text" value="${selfShop.address}"
                                                   id="address">
                                        </div>
                                        <input id="latitude" name="latitude" type="hidden" value=""/>
                                        <input id="longitude" name="longitude" type="hidden" value=""/>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                               for="name">详细信息</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <div id="container" style="height: 249px;"></div>
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                               for="name">联系人</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input class="form-control col-md-7 col-xs-12"
                                                   name="contacts" placeholder="" required="required"
                                                   type="text" value="${selfShop.contacts}" id="contacts">
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                               for="name">联系电话 </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input class="form-control col-md-7 col-xs-12"
                                                   name="phonenum" placeholder="请填写数字" required="required"
                                                   type="text" value="${selfShop.phonenum}" id="phonenum"
                                                   oninput="value=value.replace(/[^\d]/g,'')">
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                               for="name">营业时间 </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input class="form-control col-md-7 col-xs-12"
                                                   name="busintime" placeholder="" required="required"
                                                   type="text" value="${selfShop.busintime}" id="busintime">
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                               for="name">折扣信息 </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input class="form-control col-md-7 col-xs-12"
                                                   name="discount" placeholder="" required="required"
                                                   type="text" value="${selfShop.discount}" id="discount">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">店铺简介
                                            <span class="required"></span></label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
												<textarea name="introduction" id="introduction"
                                                          class="form-control">${selfShop.introduction}</textarea>
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                               for="name">所属分类 </label><span class="required"></span>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <select class="form-control" id="catid" name="catid">
                                                <option value="">综合</option>
                                                <c:forEach items="${sClassifyList}" var="s">
                                                    <option value="${s.id}"
                                                            <c:if test="${selfShop.catid == s.id}">selected</c:if>>${s.text}</option>
                                                </c:forEach>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="item form-group" id="pic1">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                               for="attestation1">证明图片1
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input class="form-control col-md-7 col-xs-12" id="attestation1"
                                                   name="attestation1" type="file"
                                                   placeholder="请先上传图片" form="formUpload">
                                        </div>
                                        <span id="button1"><a type="button" class="btn btn-default"
                                                              href="javascript:void(0)">添加</a></span>
                                    </div>
                                    <div class="item form-group" id="pic2" style="display: none">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                               for="attestation2">证明图片2
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input class="form-control col-md-7 col-xs-12" id="attestation2"
                                                   name="attestation2" type="file"
                                                   placeholder="请先上传图片" form="formUpload">
                                        </div>
                                        <span id="button2"><a type="button" class="btn btn-default"
                                                              href="javascript:void(0)">添加</a></span>
                                    </div>
                                    <div class="item form-group" id="pic3" style="display: none">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                               for="attestation3">证明图片3
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input class="form-control col-md-7 col-xs-12" id="attestation3"
                                                   name="attestation3" type="file"
                                                   placeholder="请先上传图片" form="formUpload">
                                        </div>
                                        <span id="button3"><a type="button" class="btn btn-default"
                                                              href="javascript:void(0)">添加</a></span>
                                    </div>
                                    <div class="item form-group" id="pic4" style="display: none">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                               for="attestation4">证明图片4
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input class="form-control col-md-7 col-xs-12" id="attestation4"
                                                   name="attestation4" type="file"
                                                   placeholder="请先上传图片" form="formUpload">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-md-6 col-md-offset-3">
                                            <c:if test="${selfShop.isopen == null || selfShop.isopen == 0}">
                                                <input id="revise" type="button" class="btn btn-success"
                                                       value="申请入驻"/></c:if>
                                            <c:if test="${selfShop.isopen == 1}">
                                                <input id="pass" type="button" class="btn btn-default disabled"
                                                       value="审核通过"/>
                                                <input id="revise" type="button" class="btn btn-success"
                                                       value="修改"/></c:if>
                                            <c:if test="${selfShop.isopen == 2}">
                                                <input id="loading" type="button" class="btn btn-default disabled"
                                                       value="审核中" disabled="disabled"/></c:if>
                                            <c:if test="${selfShop.isopen == 3}">
                                                <input id="lose" type="button" class="btn btn-default disabled"
                                                       value="审核失败" disabled="disabled"/></c:if>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- /page content -->
<!-- 上传图片并修改 -->
<script src="<%=basePath%>vendors/jquery/dist/jquery.min.js"></script>
<script>
    $("#button1").click(function () {
        $("#button1").css("display", "none");
        $("#pic2").css("display", "block");
    });
    $("#button2").click(function () {
        $("#button2").css("display", "none");
        $("#pic3").css("display", "block");
    });
    $("#button3").click(function () {
        $("#button3").css("display", "none");
        $("#pic4").css("display", "block");
    });
</script>
<script type="text/javascript">
    $('#revise').click(function () {
        // 上传文件
        var logoFile = $("#logoFile")[0].files[0];
        var bgFile = $("#bgFile")[0].files[0];
        var detailpic1 = $("#attestation1")[0].files[0];
        var detailpic2 = $("#attestation2")[0].files[0];
        var detailpic3 = $("#attestation3")[0].files[0];
        var detailpic4 = $("#attestation4")[0].files[0];
        var pic1 = "";
        var pic2 = "";
        var pic3 = "";
        var pic4 = "";

        if (logoFile != null || logoFile != undefined) {
            var fileName = logoFile.name.substring(logoFile.name.lastIndexOf(".") + 1).toLowerCase();
            if (fileName != "jpg" && fileName != "jpeg" && fileName != "png" && fileName != "gif") {
                alert("只能上传 .jpg .png .jpeg .gif类型的文件");
                return false;
            }
            $("#shoplogo").val(addfile(logoFile));
        }
        if (bgFile != null || bgFile != undefined) {
            var fileName = bgFile.name.substring(bgFile.name.lastIndexOf(".") + 1).toLowerCase();
            if (fileName != "jpg" && fileName != "jpeg" && fileName != "png" && fileName != "gif") {
                alert("只能上传 .jpg .png .jpeg .gif类型的文件");
                return false;
            }
            $("#shopbg").val(addfile(bgFile));
        }
        if (detailpic1 != null || detailpic1 != undefined) {
            var fileName = detailpic1.name.substring(detailpic1.name.lastIndexOf(".") + 1).toLowerCase();
            if (fileName != "jpg" && fileName != "jpeg" && fileName != "png" && fileName != "gif") {
                alert("只能上传 .jpg .png .jpeg .gif类型的文件");
                return false;
            }
            pic1 = addfile(detailpic1);
        }
        if (detailpic2 != null || detailpic2 != undefined) {
            var fileName = detailpic2.name.substring(detailpic2.name.lastIndexOf(".") + 1).toLowerCase();
            if (fileName != "jpg" && fileName != "jpeg" && fileName != "png" && fileName != "gif") {
                alert("只能上传 .jpg .png .jpeg .gif类型的文件");
                return false;
            }
            pic2 = addfile(detailpic2);
        }
        if (detailpic3 != null || detailpic3 != undefined) {
            var fileName = detailpic3.name.substring(detailpic3.name.lastIndexOf(".") + 1).toLowerCase();
            if (fileName != "jpg" && fileName != "jpeg" && fileName != "png" && fileName != "gif") {
                alert("只能上传 .jpg .png .jpeg .gif类型的文件");
                return false;
            }
            pic3 = addfile(detailpic3);
        }
        if (detailpic4 != null || detailpic4 != undefined) {
            var fileName = detailpic4.name.substring(detailpic4.name.lastIndexOf(".") + 1).toLowerCase();
            if (fileName != "jpg" && fileName != "jpeg" && fileName != "png" && fileName != "gif") {
                alert("只能上传 .jpg .png .jpeg .gif类型的文件");
                return false;
            }
            pic4 = addfile(detailpic4);
        }

        var isopen = ${isopen};

        if (isopen == 1) {
            ajaxPost(pic1, pic2, pic3, pic4);
        } else {
            addShop(pic1, pic2, pic3, pic4);
        }
    });

    function addfile(file) {
        var fm = new FormData();
        fm.append('file', file);
        $.ajax({
            url: "<%=basePath%>layfile/uploadFile1",
            type: 'POST',
            data: fm,
            async: false,
            contentType: false, //禁止设置请求类型
            processData: false, //禁止jquery对DAta数据的处理,默认会处理
            //禁止的原因是,FormData已经帮我们做了处理
            success: function (result) {
                file = result.json;
            }
        });
        return file;
    }
</script>
<script type="text/javascript">
    // ajax 对象
    function ajaxObject() {
        var xmlHttp;
        try {
            // Firefox, Opera 8.0+, Safari
            xmlHttp = new XMLHttpRequest();
        } catch (e) {
            // Internet Explorer
            try {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
                    alert("您的浏览器不支持AJAX！");
                    return false;
                }
            }
        }
        return xmlHttp;
    }

    // ajax post请求：
    function ajaxPost(pic1, pic2, pic3, pic4) {
        var id = $("#id").val();
        var shopname = $("#shopname").val();
        var shoplogo = $("#shoplogo").val();
        var shopbg = $("#shopbg").val();
        var address = $("#address").val();
        var contacts = $("#contacts").val();
        var phonenum = $("#phonenum").val();
        var introduction = $("#introduction").val();
        var latitude = $("#latitude").val();
        var longitude = $("#longitude").val();
        var busintime = $("#busintime").val();
        var discount = $("#discount").val();
        var catid = $("#catid").val();
        var ajax = ajaxObject();
        ajax.open("post", "updateSelfShop?id=" + id +
            "&phonenum=" + phonenum +
            "&shopname=" + shopname +
            "&shoplogo=" + shoplogo +
            "&shopbg=" + shopbg +
            "&address=" + address +
            "&contacts=" + contacts +
            "&introduction=" + introduction +
            "&latitude=" + latitude +
            "&longitude=" + longitude +
            "&busintime=" + busintime +
            "&discount=" + discount +
            "&catid=" + catid +
            "&attestation1=" + pic1 +
            "&attestation2=" + pic2 +
            "&attestation3=" + pic3 +
            "&attestation4=" + pic4, false);
        ajax.setRequestHeader("Content-Type",
            "application/x-www-form-urlencoded");
        ajax.onreadystatechange = function () {
            if (ajax.readyState == 4) {
                if (ajax.status == 200) {
                    var result = ajax.responseText;
                    if (result == "success") {
                        //请求成功
                        alert("修改成功");
                        location.href = "selfShop";
                    } else {
                        //创建失败
                        alert(result);
                    }
                } else if (ajax.status == 0) {
                    //请求失败
                    alert("您使用的火狐浏览器不支持本次操作，请更换浏览器重试");
                } else {
                    //请求失败
                    alert("请求终止，请检查操作或联系客服咨询" + ajax.status);
                }
            } else {
            }
        };
        ajax.send();
    }

    function addShop(pic1, pic2, pic3, pic4) {
        var shopname = $("#shopname").val();
        var shoplogo = $("#shoplogo").val();
        var shopbg = $("#shopbg").val();
        var address = $("#address").val();
        var contacts = $("#contacts").val();
        var phonenum = $("#phonenum").val();
        var introduction = $("#introduction").val();
        var latitude = $("#latitude").val();
        var longitude = $("#longitude").val();
        var busintime = $("#busintime").val();
        var discount = $("#discount").val();
        var catid = $("#catid").val();
        var ajax = ajaxObject();
        ajax.open("post", "insertSelfShop?shopname=" + shopname +
            "&shoplogo=" + shoplogo +
            "&shopbg=" + shopbg +
            "&address=" + address +
            "&contacts=" + contacts +
            "&introduction=" + introduction +
            "&latitude=" + latitude +
            "&longitude=" + longitude +
            "&busintime=" + busintime +
            "&discount=" + discount +
            "&catid=" + catid +
            "&phonenum=" + phonenum +
            "&attestation1=" + pic1 +
            "&attestation2=" + pic2 +
            "&attestation3=" + pic3 +
            "&attestation4=" + pic4, true);
        ajax.setRequestHeader("Content-Type",
            "application/x-www-form-urlencoded");
        ajax.onreadystatechange = function () {
            if (ajax.readyState == 4) {
                if (ajax.status == 200) {
                    var result = ajax.responseText;
                    if (result == "success") {
                        //请求成功
                        alert("申请成功,请耐心等待申请结果");
                        location.href = "selfShop";
                    } else {
                        //创建失败
                        alert(result);
                    }
                } else if (ajax.status == 0) {
                    //请求失败
                    alert("您使用的火狐浏览器不支持本次操作，请更换浏览器重试");
                } else {
                    //请求失败
                    alert("请求终止，请检查操作或联系客服咨询" + ajax.status);
                }
            } else {
            }
        };
        ajax.send();
    }
</script>
<script type="text/javascript">
    // 百度地图API功能
    var map = new BMap.Map("container");
    var address = $('#address').val();
    if (address.length == 0) {
        map.centerAndZoom('杭州', 16);
    } else {
        map.centerAndZoom(address, 16);
    }
    map.enableScrollWheelZoom(); //启用滚轮放大缩小，默认禁用
    map.enableContinuousZoom(); //启用地图惯性拖拽，默认禁用
    map.addControl(new BMap.NavigationControl()); //添加默认缩放平移控件
    map.addControl(new BMap.OverviewMapControl()); //添加默认缩略地图控件

    var localSearch = new BMap.LocalSearch(map);
    $('#address').blur(function (event) {
        var keyword = $('#address').val();
        if (keyword.length == 0) {
            alert("请输入店铺地址信息");
            return false;
        }
        map.clearOverlays();//清空原来的标注
        localSearch.setSearchCompleteCallback(function (searchResult) {
            var poi = searchResult.getPoi(0);
            $("#latitude").val(poi.point.lng);
            $("#longitude").val(poi.point.lat);
            map.centerAndZoom(poi.point, 16);
            map.addOverlay(new BMap.Marker(new BMap.Point(poi.point.lng, poi.point.lat))); // 创建标注
        });
        localSearch.search(keyword);
    });
</script>
<!-- Bootstrap -->
<script src="<%=basePath%>vendors/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- FastClick -->
<script src="<%=basePath%>vendors/fastclick/lib/fastclick.js"></script>
<!-- NProgress -->
<script src="<%=basePath%>vendors/nprogress/nprogress.js"></script>
<!-- bootstrap-daterangepicker -->
<script src="<%=basePath%>vendors/moment/min/moment.min.js"></script>
<script
        src="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.js"></script>
<!-- Chart.js -->
<script src="<%=basePath%>vendors/Chart.js/dist/Chart.min.js"></script>
<!-- Custom Theme Scripts -->
<script src="<%=basePath%>build/js/custom.min.js"></script>
</body>
</html>